{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.chdir('../')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from config import conf\n",
    "import pandas as pd\n",
    "import os\n",
    "from os.path import join\n",
    "import re\n",
    "import numpy as np\n",
    "FEATURE_ROOT_DIR = conf.get('linux_dir', 'feature_root_dir')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[01;34m/home/njuciairs/wangshuai/competitions/finance_features/\u001b[00m\r\n",
      "├── \u001b[01;34mBertSentiEntity_cross\u001b[00m\r\n",
      "│   ├── feature_split 1\r\n",
      "│   ├── feature_split 2\r\n",
      "│   ├── feature_split 3\r\n",
      "│   ├── feature_split 4\r\n",
      "│   ├── feature_split 5\r\n",
      "│   ├── feature_split 6\r\n",
      "│   ├── feature_split 7\r\n",
      "│   ├── feature_split 8\r\n",
      "│   ├── feature_split 9\r\n",
      "│   ├── test_features_round2_version_goodremove 1\r\n",
      "│   ├── test_features_round2_version_goodremove 2\r\n",
      "│   ├── test_features_round2_version_goodremove 3\r\n",
      "│   ├── test_features_round2_version_goodremove 4\r\n",
      "│   ├── test_features_round2_version_goodremove 5\r\n",
      "│   ├── test_features_round2_version_goodremove 6\r\n",
      "│   ├── test_features_round2_version_goodremove 7\r\n",
      "│   ├── test_features_round2_version_goodremove 8\r\n",
      "│   ├── test_features_round2_version_goodremove 9\r\n",
      "│   ├── test_features_version 1\r\n",
      "│   ├── test_features_version 2\r\n",
      "│   ├── test_features_version 3\r\n",
      "│   ├── test_features_version 4\r\n",
      "│   ├── test_features_version 5\r\n",
      "│   ├── test_features_version 6\r\n",
      "│   ├── test_features_version 7\r\n",
      "│   ├── test_features_version 8\r\n",
      "│   ├── test_features_version 9\r\n",
      "│   ├── test_features_version_goodremove 1\r\n",
      "│   ├── test_features_version_goodremove 2\r\n",
      "│   ├── test_features_version_goodremove 3\r\n",
      "│   ├── test_features_version_goodremove 4\r\n",
      "│   ├── test_features_version_goodremove 5\r\n",
      "│   ├── test_features_version_goodremove 6\r\n",
      "│   ├── test_features_version_goodremove 7\r\n",
      "│   ├── test_features_version_goodremove 8\r\n",
      "│   └── test_features_version_goodremove 9\r\n",
      "├── \u001b[01;34mmulti_class_cross1\u001b[00m\r\n",
      "│   ├── feature_split 1\r\n",
      "│   ├── feature_split 2\r\n",
      "│   ├── feature_split 3\r\n",
      "│   ├── feature_split 4\r\n",
      "│   ├── feature_split 5\r\n",
      "│   ├── feature_split 6\r\n",
      "│   ├── feature_split 7\r\n",
      "│   ├── feature_split 8\r\n",
      "│   ├── feature_split 9\r\n",
      "│   ├── test_features_round2_version 1\r\n",
      "│   ├── test_features_round2_version 2\r\n",
      "│   ├── test_features_round2_version 3\r\n",
      "│   ├── test_features_round2_version 4\r\n",
      "│   ├── test_features_round2_version 5\r\n",
      "│   ├── test_features_round2_version 6\r\n",
      "│   ├── test_features_round2_version 7\r\n",
      "│   ├── test_features_round2_version 8\r\n",
      "│   ├── test_features_round2_version 9\r\n",
      "│   ├── test_features_version 1\r\n",
      "│   ├── test_features_version 2\r\n",
      "│   ├── test_features_version 3\r\n",
      "│   ├── test_features_version 4\r\n",
      "│   ├── test_features_version 5\r\n",
      "│   ├── test_features_version 6\r\n",
      "│   ├── test_features_version 7\r\n",
      "│   ├── test_features_version 8\r\n",
      "│   └── test_features_version 9\r\n",
      "├── \u001b[01;34mmulti_class_cross_roberta\u001b[00m\r\n",
      "│   ├── feature_split 1\r\n",
      "│   ├── feature_split 2\r\n",
      "│   ├── feature_split 3\r\n",
      "│   ├── feature_split 4\r\n",
      "│   ├── feature_split 5\r\n",
      "│   ├── feature_split 6\r\n",
      "│   ├── feature_split 7\r\n",
      "│   ├── feature_split 8\r\n",
      "│   ├── feature_split 9\r\n",
      "│   ├── test_features_round2_version 1\r\n",
      "│   ├── test_features_round2_version 2\r\n",
      "│   ├── test_features_round2_version 3\r\n",
      "│   ├── test_features_round2_version 4\r\n",
      "│   ├── test_features_round2_version 5\r\n",
      "│   ├── test_features_round2_version 6\r\n",
      "│   ├── test_features_round2_version 7\r\n",
      "│   ├── test_features_round2_version 8\r\n",
      "│   ├── test_features_round2_version 9\r\n",
      "│   ├── test_features_version 1\r\n",
      "│   ├── test_features_version 2\r\n",
      "│   ├── test_features_version 3\r\n",
      "│   ├── test_features_version 4\r\n",
      "│   ├── test_features_version 5\r\n",
      "│   ├── test_features_version 6\r\n",
      "│   ├── test_features_version 7\r\n",
      "│   ├── test_features_version 8\r\n",
      "│   └── test_features_version 9\r\n",
      "├── \u001b[01;34mpredict_features\u001b[00m\r\n",
      "│   ├── mc_rb.csv\r\n",
      "│   ├── mc_rb_se.csv\r\n",
      "│   ├── mc_rb_se_test.csv\r\n",
      "│   ├── mc_rb_test.csv\r\n",
      "│   └── rc_rb.csv\r\n",
      "└── \u001b[01;34msenti_entity_goodremove\u001b[00m\r\n",
      "    ├── feature_split 1\r\n",
      "    ├── feature_split 2\r\n",
      "    ├── feature_split 3\r\n",
      "    ├── feature_split 4\r\n",
      "    ├── feature_split 5\r\n",
      "    ├── feature_split 6\r\n",
      "    ├── feature_split 7\r\n",
      "    ├── feature_split 8\r\n",
      "    └── feature_split 9\r\n",
      "\r\n",
      "5 directories, 104 files\r\n"
     ]
    }
   ],
   "source": [
    "!tree $FEATURE_ROOT_DIR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#提取multi_class_cross1新feature\n",
    "def get_feature_for_multi_class_cross1(split_id):\n",
    "    from data_utils.bert_multi_class_data import get_train_val_data_loader,load_train_val_dataset_cross,TestEntityDataset\n",
    "    val_df, train_df  = load_train_val_dataset_cross(test_number=split_id, cross_number=9)\n",
    "    test_df = val_df\n",
    "    test_dataset = TestEntityDataset(test_df, max_len=400)\n",
    "    texts = [sample.text for sample in test_dataset]\n",
    "    entity = [t.split('[SEP]')[0][5:] for t in texts]\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'multi_class_cross1','feature_split %d'%split_id))\n",
    "    feature_df['key_entity'] = entity\n",
    "    feature_df['predict_features'] = feature_df['predict_features'].map(lambda x:eval(re.search(r'(\\[.*\\])',x).group()))\n",
    "    return feature_df\n",
    "\n",
    "def get_test_feature_for_multi_class_cross1(split_id):\n",
    "    from data_utils.bert_multi_class_data import TestEntityDataset\n",
    "    from data_utils.basic_data import load_basic_dataset\n",
    "    test_df = load_basic_dataset('test')\n",
    "    test_dataset = TestEntityDataset(test_df, max_len=400)\n",
    "    texts = [sample.text for sample in test_dataset]\n",
    "    entity = [t.split('[SEP]')[0][5:] for t in texts]\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'multi_class_cross1','test_features_round2_version %d'%split_id))\n",
    "    feature_df['key_entity'] = entity\n",
    "    feature_df['predict_test_features'] = feature_df['predict_test_features'].map(lambda x:eval(re.search(r'(\\[.*\\])',x).group()))\n",
    "    return feature_df.sort_values(['id','key_entity']).reset_index(drop=True)\n",
    "\n",
    "# df = get_test_feature_for_multi_class_cross1(1)\n",
    "# df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#提取multi_class_cross_roberta新feature\n",
    "def get_feature_for_multi_class_roberta(split_id):\n",
    "    from data_utils.bert_multi_class_data_roberta import get_train_val_data_loader,load_train_val_dataset_cross,TestEntityDataset\n",
    "    val_df, train_df  = load_train_val_dataset_cross(test_number=split_id, cross_number=9)\n",
    "    test_df = val_df\n",
    "    test_dataset = TestEntityDataset(test_df, max_len=400)\n",
    "    texts = [sample.text for sample in test_dataset]\n",
    "    entity = [t.split('[SEP]')[0][5:] for t in texts]\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'multi_class_cross_roberta','feature_split %d'%split_id))\n",
    "    feature_df['key_entity'] = entity\n",
    "    feature_df['predict_features'] = feature_df['predict_features'].map(lambda x:eval(re.search(r'(\\[.*\\])',x).group()))\n",
    "    return feature_df\n",
    "\n",
    "def get_test_feature_for_multi_class_roberta(split_id):\n",
    "    from data_utils.bert_multi_class_data_roberta import TestEntityDataset\n",
    "    from data_utils.basic_data import load_basic_dataset\n",
    "    test_df = load_basic_dataset('test')\n",
    "    test_dataset = TestEntityDataset(test_df, max_len=400)\n",
    "    texts = [sample.text for sample in test_dataset]\n",
    "    entity = [t.split('[SEP]')[0][5:] for t in texts]\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'multi_class_cross_roberta','test_features_round2_version %d'%split_id))\n",
    "    feature_df['key_entity'] = entity\n",
    "    feature_df['predict_test_features'] = feature_df['predict_test_features'].map(lambda x:eval(re.search(r'(\\[.*\\])',x).group()))\n",
    "    return feature_df.sort_values(['id','key_entity']).reset_index(drop=True)\n",
    "# df = get_test_feature_for_multi_class_roberta(3)\n",
    "# df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#提取BertSentiEntity_cross新feature\n",
    "def get_feature_for_BertSentiEntity_cross(split_id):\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'BertSentiEntity_cross','feature_split %d'%split_id))\n",
    "    feature_df['negative'] = feature_df['negative'].map(lambda x:eval(x))\n",
    "    feature_df['predict'] = feature_df['predict'].map(lambda x:eval(x))\n",
    "    feature_df['entity_list'] = feature_df['entity_list'].map(lambda x:eval(x))\n",
    "    return feature_df\n",
    "\n",
    "def get_test_feature_for_BertSentiEntity_cross(split_id):\n",
    "    feature_df = pd.read_csv(join(FEATURE_ROOT_DIR,'BertSentiEntity_cross','test_features_round2_version_goodremove %d'%split_id))\n",
    "    feature_df['negative'] = feature_df['negative'].map(lambda x:eval(x))\n",
    "    feature_df['predict'] = feature_df['predict'].map(lambda x:eval(x))\n",
    "    feature_df['entity_list'] = feature_df['entity_list'].map(lambda x:eval(x))\n",
    "    return feature_df.sort_values(['id']).reset_index(drop=True)\n",
    "# df = get_test_feature_for_BertSentiEntity_cross(1)\n",
    "# df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#new_feature_sample = {(id,entity):(multiclass1_predict,roberta_predict,sentientity_predict,sentientity_sentence)}\n",
    "#整合新的feature\n",
    "class NewFeatureSample:\n",
    "    def __init__(self,id,entity,mc_predict=None,rb_predict=None,se_entity=None,se_sentence=None):\n",
    "        self.id = id\n",
    "        self.entity = entity\n",
    "        self.mc_predict = mc_predict\n",
    "        self.rb_predict = rb_predict\n",
    "        self.se_entity = se_entity\n",
    "        self.se_sentence = se_sentence\n",
    "    def get_tuple(self):\n",
    "        return (self.id,self.entity,self.mc_predict,self.rb_predict,self.se_entity,self.se_sentence)\n",
    "    def __str__(self):\n",
    "        return str((self.id,self.entity,self.mc_predict,self.rb_predict,self.se_entity,self.se_sentence))\n",
    "    def __repr__(self):\n",
    "        return self.__str__()\n",
    "    \n",
    "def make_mc_rb_features(): \n",
    "    new_feature_samples = {}\n",
    "    for i in range(1,10):\n",
    "        df_mc = get_feature_for_multi_class_cross1(i)\n",
    "        for id,predict_features,key_entity in df_mc.values:\n",
    "            key = (id,key_entity) \n",
    "            if key not in new_feature_samples:\n",
    "                new_feature_samples[key] = NewFeatureSample(id=id,entity=key_entity,mc_predict=predict_features)\n",
    "            else:\n",
    "                new_feature_samples[key].mc_predict = predict_features\n",
    "    for i in range(1,10):\n",
    "        df_rb = get_feature_for_multi_class_roberta(i)\n",
    "        for id,predict_features,key_entity in df_rb.values:\n",
    "            key = (id,key_entity) \n",
    "            if key not in new_feature_samples:\n",
    "                new_feature_samples[key] = NewFeatureSample(id=id,entity=key_entity,rb_predict=predict_features)\n",
    "            else:\n",
    "                new_feature_samples[key].rb_predict = predict_features\n",
    "    mc_rb_features = pd.DataFrame([sample.get_tuple() for sample in new_feature_samples.values()],columns=['id','entity','mc_predict','rb_predict','se_entity','se_sentence'])\n",
    "    mc_rb_features_df = mc_rb_features[['id','entity','mc_predict','rb_predict']]\n",
    "    return new_feature_samples,mc_rb_features_df\n",
    "def make_mc_rb_test_features(): \n",
    "    new_feature_samples = {}\n",
    "    df_mc = get_test_feature_for_multi_class_cross1(1)\n",
    "    values =[get_test_feature_for_multi_class_cross1(i)['predict_test_features'].values.tolist() for i in range(1,10)]\n",
    "    df_mc['predict_test_features'] = np.mean(values,axis=0).tolist()\n",
    "    for id,predict_features,key_entity in df_mc.values:\n",
    "        key = (id,key_entity) \n",
    "        if key not in new_feature_samples:\n",
    "            new_feature_samples[key] = NewFeatureSample(id=id,entity=key_entity,mc_predict=predict_features)\n",
    "        else:\n",
    "            new_feature_samples[key].mc_predict = predict_features\n",
    "            \n",
    "    df_rb = get_test_feature_for_multi_class_roberta(1)\n",
    "    values =[get_test_feature_for_multi_class_roberta(i)['predict_test_features'].values.tolist() for i in range(1,10)]\n",
    "    df_rb['predict_test_features'] = np.mean(values,axis=0).tolist()\n",
    "    \n",
    "    for id,predict_features,key_entity in df_rb.values:\n",
    "        key = (id,key_entity) \n",
    "        if key not in new_feature_samples:\n",
    "            new_feature_samples[key] = NewFeatureSample(id=id,entity=key_entity,rb_predict=predict_features)\n",
    "        else:\n",
    "            new_feature_samples[key].rb_predict = predict_features\n",
    "    mc_rb_features = pd.DataFrame([sample.get_tuple() for sample in new_feature_samples.values()],columns=['id','entity','mc_predict','rb_predict','se_entity','se_sentence'])\n",
    "    mc_rb_test_features_df = mc_rb_features[['id','entity','mc_predict','rb_predict']]\n",
    "    return new_feature_samples,mc_rb_test_features_df\n",
    "# _,mc_rb_test_features_df = make_mc_rb_test_features()\n",
    "# mc_rb_test_features_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# _,mc_rb_features = make_mc_rb_features()\n",
    "# mc_rb_features.to_csv('new_features/mc_rb_features.csv',index=False)\n",
    "# mc_rb_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def make_mc_rb_se_features():\n",
    "    new_feature_samples,_ = make_mc_rb_features()\n",
    "    for i in range(1,10):\n",
    "        se_df = get_feature_for_BertSentiEntity_cross(i)\n",
    "        for id,negative,se_entity_logits,entity_list in se_df.values:\n",
    "            for entity in entity_list:\n",
    "                key = (id,entity)\n",
    "                if key not in  new_feature_samples:\n",
    "                    new_feature_samples[key] = NewFeatureSample(id,entity,se_sentence=negative)\n",
    "                else:\n",
    "                    new_feature_samples[key].se_sentence = negative\n",
    "            for entity_logit,entity in zip(se_entity_logits,entity_list):\n",
    "                key = (id,entity)\n",
    "                if key not in  new_feature_samples:\n",
    "                    new_feature_samples[key] = NewFeatureSample(id,entity,se_entity==entity_logit)\n",
    "                else:\n",
    "                    new_feature_samples[key].se_entity = entity_logit\n",
    "    mc_rb_se_df = pd.DataFrame([sample.get_tuple() for sample in new_feature_samples.values()],columns=['id','entity','mc_predict','rb_predict','se_entity','se_sentence'])\n",
    "    return new_feature_samples,mc_rb_se_df\n",
    "\n",
    "def make_mc_rb_se_test_features():\n",
    "    new_feature_samples,_ = make_mc_rb_test_features()\n",
    "    se_df = get_test_feature_for_BertSentiEntity_cross(1)\n",
    "    se_df['negative'] = np.mean(np.array([get_test_feature_for_BertSentiEntity_cross(i)['negative'].values.tolist() for i in range(1,10)]),axis=0).tolist()\n",
    "    \n",
    "    mean_rs = []\n",
    "    values = [get_test_feature_for_BertSentiEntity_cross(i)['predict'].values.tolist() for i in range(1,10) ]\n",
    "    for i in range(len(values[0])):\n",
    "        lists = [rs[i] for rs in values]\n",
    "        mean_rs.append(np.mean(lists,axis=0).tolist())\n",
    "    se_df['predict'] = mean_rs\n",
    "    \n",
    "    for id,negative,se_entity_logits,entity_list in se_df.values:\n",
    "        for entity in entity_list:\n",
    "            key = (id,entity)\n",
    "            if key not in  new_feature_samples:\n",
    "                new_feature_samples[key] = NewFeatureSample(id,entity,se_sentence=negative)\n",
    "            else:\n",
    "                new_feature_samples[key].se_sentence = negative\n",
    "        for entity_logit,entity in zip(se_entity_logits,entity_list):\n",
    "            key = (id,entity)\n",
    "            if key not in  new_feature_samples:\n",
    "                new_feature_samples[key] = NewFeatureSample(id,entity,se_entity==entity_logit)\n",
    "            else:\n",
    "                new_feature_samples[key].se_entity = entity_logit\n",
    "    mc_rb_se_test_df = pd.DataFrame([sample.get_tuple() for sample in new_feature_samples.values()],columns=['id','entity','mc_predict','rb_predict','se_entity','se_sentence'])\n",
    "    return new_feature_samples,mc_rb_se_test_df\n",
    "# _,mc_rb_se_test_df = make_mc_rb_se_test_features()\n",
    "# mc_rb_se_test_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# mc_rb_se_df.to_csv('new_features/mc_rb_se_features.csv',index=False)\n",
    "# mc_rb_se_df.head()\n",
    "feature_save_path = join(FEATURE_ROOT_DIR,'predict_features')\n",
    "if not os.path.exists(feature_save_path):\n",
    "    os.mkdir(feature_save_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>entity</th>\n",
       "      <th>mc_predict</th>\n",
       "      <th>rb_predict</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>ab34b84d</td>\n",
       "      <td>钱宝网</td>\n",
       "      <td>[-3.6999, -2.152, 6.0101]</td>\n",
       "      <td>[-4.4489, -3.5528, 6.5909]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ab34b84d</td>\n",
       "      <td>钱宝</td>\n",
       "      <td>[-3.7304, -2.1885, 6.0154]</td>\n",
       "      <td>[-4.5253, -3.4793, 6.6106]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>bf2eb98d</td>\n",
       "      <td>京东白条</td>\n",
       "      <td>[7.2469, -3.2973, -3.7051]</td>\n",
       "      <td>[8.4592, -3.2981, -3.6542]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>e4d2aabf</td>\n",
       "      <td>巨石强森</td>\n",
       "      <td>[-4.1542, -1.7876, 5.9733]</td>\n",
       "      <td>[-4.9172, -3.0293, 6.3409]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>e4d2aabf</td>\n",
       "      <td>中弘</td>\n",
       "      <td>[-4.4256, -1.5073, 5.834]</td>\n",
       "      <td>[-4.8672, -2.9712, 6.1653]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         id entity                  mc_predict                  rb_predict\n",
       "0  ab34b84d    钱宝网   [-3.6999, -2.152, 6.0101]  [-4.4489, -3.5528, 6.5909]\n",
       "1  ab34b84d     钱宝  [-3.7304, -2.1885, 6.0154]  [-4.5253, -3.4793, 6.6106]\n",
       "2  bf2eb98d   京东白条  [7.2469, -3.2973, -3.7051]  [8.4592, -3.2981, -3.6542]\n",
       "3  e4d2aabf   巨石强森  [-4.1542, -1.7876, 5.9733]  [-4.9172, -3.0293, 6.3409]\n",
       "4  e4d2aabf     中弘   [-4.4256, -1.5073, 5.834]  [-4.8672, -2.9712, 6.1653]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#mc_rb  features\n",
    "_,mc_rb_features = make_mc_rb_features()\n",
    "\n",
    "mc_rb_features.to_csv(join(feature_save_path,'mc_rb.csv'),index=False)\n",
    "mc_rb_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>entity</th>\n",
       "      <th>mc_predict</th>\n",
       "      <th>rb_predict</th>\n",
       "      <th>se_entity</th>\n",
       "      <th>se_sentence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>ab34b84d</td>\n",
       "      <td>钱宝网</td>\n",
       "      <td>[-3.6999, -2.152, 6.0101]</td>\n",
       "      <td>[-4.4489, -3.5528, 6.5909]</td>\n",
       "      <td>[-5.958427429199219, 5.599534511566162]</td>\n",
       "      <td>[-6.357543468475342, 5.901674747467041]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ab34b84d</td>\n",
       "      <td>钱宝</td>\n",
       "      <td>[-3.7304, -2.1885, 6.0154]</td>\n",
       "      <td>[-4.5253, -3.4793, 6.6106]</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>bf2eb98d</td>\n",
       "      <td>京东白条</td>\n",
       "      <td>[7.2469, -3.2973, -3.7051]</td>\n",
       "      <td>[8.4592, -3.2981, -3.6542]</td>\n",
       "      <td>[5.175036430358887, -5.105545997619629]</td>\n",
       "      <td>[4.806569576263428, -5.588745594024658]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>e4d2aabf</td>\n",
       "      <td>巨石强森</td>\n",
       "      <td>[-4.1542, -1.7876, 5.9733]</td>\n",
       "      <td>[-4.9172, -3.0293, 6.3409]</td>\n",
       "      <td>[-5.900289058685303, 5.647790908813477]</td>\n",
       "      <td>[-6.754196643829346, 7.464597225189209]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>e4d2aabf</td>\n",
       "      <td>中弘</td>\n",
       "      <td>[-4.4256, -1.5073, 5.834]</td>\n",
       "      <td>[-4.8672, -2.9712, 6.1653]</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         id entity                  mc_predict                  rb_predict  \\\n",
       "0  ab34b84d    钱宝网   [-3.6999, -2.152, 6.0101]  [-4.4489, -3.5528, 6.5909]   \n",
       "1  ab34b84d     钱宝  [-3.7304, -2.1885, 6.0154]  [-4.5253, -3.4793, 6.6106]   \n",
       "2  bf2eb98d   京东白条  [7.2469, -3.2973, -3.7051]  [8.4592, -3.2981, -3.6542]   \n",
       "3  e4d2aabf   巨石强森  [-4.1542, -1.7876, 5.9733]  [-4.9172, -3.0293, 6.3409]   \n",
       "4  e4d2aabf     中弘   [-4.4256, -1.5073, 5.834]  [-4.8672, -2.9712, 6.1653]   \n",
       "\n",
       "                                 se_entity  \\\n",
       "0  [-5.958427429199219, 5.599534511566162]   \n",
       "1                                     None   \n",
       "2  [5.175036430358887, -5.105545997619629]   \n",
       "3  [-5.900289058685303, 5.647790908813477]   \n",
       "4                                     None   \n",
       "\n",
       "                               se_sentence  \n",
       "0  [-6.357543468475342, 5.901674747467041]  \n",
       "1                                     None  \n",
       "2  [4.806569576263428, -5.588745594024658]  \n",
       "3  [-6.754196643829346, 7.464597225189209]  \n",
       "4                                     None  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#mc_rb_se  features\n",
    "_,mc_rb_se_features = make_mc_rb_se_features()\n",
    "\n",
    "mc_rb_se_features.to_csv(join(feature_save_path,'mc_rb_se.csv'),index=False)\n",
    "mc_rb_se_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>entity</th>\n",
       "      <th>mc_predict</th>\n",
       "      <th>rb_predict</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>13001</td>\n",
       "      <td>北京华赢凯来资产管理有限公司</td>\n",
       "      <td>[-4.753866666666665, -2.822511111111111, 6.420...</td>\n",
       "      <td>[-4.7957888888888895, -2.140622222222222, 6.04...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>13001</td>\n",
       "      <td>华赢凯来</td>\n",
       "      <td>[-4.493599999999999, -3.188066666666667, 6.621...</td>\n",
       "      <td>[-4.388288888888889, -2.6135666666666664, 6.20...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>13002</td>\n",
       "      <td>米袋</td>\n",
       "      <td>[-4.129611111111112, -3.3089111111111107, 6.39...</td>\n",
       "      <td>[-4.088477777777778, -2.906555555555556, 6.186...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>13002</td>\n",
       "      <td>米袋计划</td>\n",
       "      <td>[-4.307455555555555, -3.124377777777778, 6.377...</td>\n",
       "      <td>[-4.336255555555557, -2.6269, 6.1552333333333324]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>13003</td>\n",
       "      <td>易通</td>\n",
       "      <td>[-4.388744444444445, -3.2579777777777785, 6.60...</td>\n",
       "      <td>[-4.302955555555555, -2.614533333333333, 6.098...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id          entity                                         mc_predict  \\\n",
       "0  13001  北京华赢凯来资产管理有限公司  [-4.753866666666665, -2.822511111111111, 6.420...   \n",
       "1  13001            华赢凯来  [-4.493599999999999, -3.188066666666667, 6.621...   \n",
       "2  13002              米袋  [-4.129611111111112, -3.3089111111111107, 6.39...   \n",
       "3  13002            米袋计划  [-4.307455555555555, -3.124377777777778, 6.377...   \n",
       "4  13003              易通  [-4.388744444444445, -3.2579777777777785, 6.60...   \n",
       "\n",
       "                                          rb_predict  \n",
       "0  [-4.7957888888888895, -2.140622222222222, 6.04...  \n",
       "1  [-4.388288888888889, -2.6135666666666664, 6.20...  \n",
       "2  [-4.088477777777778, -2.906555555555556, 6.186...  \n",
       "3  [-4.336255555555557, -2.6269, 6.1552333333333324]  \n",
       "4  [-4.302955555555555, -2.614533333333333, 6.098...  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#mc_rb  test features\n",
    "_,mc_rb_test_features = make_mc_rb_test_features()\n",
    "\n",
    "mc_rb_test_features.to_csv(join(feature_save_path,'mc_rb_test_round2.csv'),index=False)\n",
    "mc_rb_test_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>entity</th>\n",
       "      <th>mc_predict</th>\n",
       "      <th>rb_predict</th>\n",
       "      <th>se_entity</th>\n",
       "      <th>se_sentence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>13001</td>\n",
       "      <td>北京华赢凯来资产管理有限公司</td>\n",
       "      <td>[-4.753866666666665, -2.822511111111111, 6.420...</td>\n",
       "      <td>[-4.7957888888888895, -2.140622222222222, 6.04...</td>\n",
       "      <td>[-5.396915833155314, 5.279685868157281]</td>\n",
       "      <td>[-6.123909950256348, 6.0241409407721624]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>13001</td>\n",
       "      <td>华赢凯来</td>\n",
       "      <td>[-4.493599999999999, -3.188066666666667, 6.621...</td>\n",
       "      <td>[-4.388288888888889, -2.6135666666666664, 6.20...</td>\n",
       "      <td>[-5.317468378278944, 5.2545102967156305]</td>\n",
       "      <td>[-6.123909950256348, 6.0241409407721624]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>13002</td>\n",
       "      <td>米袋</td>\n",
       "      <td>[-4.129611111111112, -3.3089111111111107, 6.39...</td>\n",
       "      <td>[-4.088477777777778, -2.906555555555556, 6.186...</td>\n",
       "      <td>[-5.148562325371636, 5.029434363047282]</td>\n",
       "      <td>[-5.821461889478895, 5.743192964129978]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>13002</td>\n",
       "      <td>米袋计划</td>\n",
       "      <td>[-4.307455555555555, -3.124377777777778, 6.377...</td>\n",
       "      <td>[-4.336255555555557, -2.6269, 6.1552333333333324]</td>\n",
       "      <td>[-5.138198958502875, 5.058905707465278]</td>\n",
       "      <td>[-5.821461889478895, 5.743192964129978]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>13003</td>\n",
       "      <td>易通</td>\n",
       "      <td>[-4.388744444444445, -3.2579777777777785, 6.60...</td>\n",
       "      <td>[-4.302955555555555, -2.614533333333333, 6.098...</td>\n",
       "      <td>[1.0753716627756755, -0.9545230070749918]</td>\n",
       "      <td>[-5.94271797604031, 5.822430557674831]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      id          entity                                         mc_predict  \\\n",
       "0  13001  北京华赢凯来资产管理有限公司  [-4.753866666666665, -2.822511111111111, 6.420...   \n",
       "1  13001            华赢凯来  [-4.493599999999999, -3.188066666666667, 6.621...   \n",
       "2  13002              米袋  [-4.129611111111112, -3.3089111111111107, 6.39...   \n",
       "3  13002            米袋计划  [-4.307455555555555, -3.124377777777778, 6.377...   \n",
       "4  13003              易通  [-4.388744444444445, -3.2579777777777785, 6.60...   \n",
       "\n",
       "                                          rb_predict  \\\n",
       "0  [-4.7957888888888895, -2.140622222222222, 6.04...   \n",
       "1  [-4.388288888888889, -2.6135666666666664, 6.20...   \n",
       "2  [-4.088477777777778, -2.906555555555556, 6.186...   \n",
       "3  [-4.336255555555557, -2.6269, 6.1552333333333324]   \n",
       "4  [-4.302955555555555, -2.614533333333333, 6.098...   \n",
       "\n",
       "                                   se_entity  \\\n",
       "0    [-5.396915833155314, 5.279685868157281]   \n",
       "1   [-5.317468378278944, 5.2545102967156305]   \n",
       "2    [-5.148562325371636, 5.029434363047282]   \n",
       "3    [-5.138198958502875, 5.058905707465278]   \n",
       "4  [1.0753716627756755, -0.9545230070749918]   \n",
       "\n",
       "                                se_sentence  \n",
       "0  [-6.123909950256348, 6.0241409407721624]  \n",
       "1  [-6.123909950256348, 6.0241409407721624]  \n",
       "2   [-5.821461889478895, 5.743192964129978]  \n",
       "3   [-5.821461889478895, 5.743192964129978]  \n",
       "4    [-5.94271797604031, 5.822430557674831]  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#mc_rb_se test features\n",
    "_,mc_rb_se_test_features = make_mc_rb_se_test_features()\n",
    "\n",
    "mc_rb_se_test_features.to_csv(join(feature_save_path,'mc_rb_se_test_round2.csv'),index=False)\n",
    "mc_rb_se_test_features.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
